// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexManagement;

public sealed partial class IndexRouting
{
	[JsonInclude, JsonPropertyName("allocation")]
	public Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocation? Allocation { get; set; }
	[JsonInclude, JsonPropertyName("rebalance")]
	public Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalance? Rebalance { get; set; }
}

public sealed partial class IndexRoutingDescriptor : SerializableDescriptor<IndexRoutingDescriptor>
{
	internal IndexRoutingDescriptor(Action<IndexRoutingDescriptor> configure) => configure.Invoke(this);

	public IndexRoutingDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocation? AllocationValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocationDescriptor AllocationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocationDescriptor> AllocationDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalance? RebalanceValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalanceDescriptor RebalanceDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalanceDescriptor> RebalanceDescriptorAction { get; set; }

	public IndexRoutingDescriptor Allocation(Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocation? allocation)
	{
		AllocationDescriptor = null;
		AllocationDescriptorAction = null;
		AllocationValue = allocation;
		return Self;
	}

	public IndexRoutingDescriptor Allocation(Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocationDescriptor descriptor)
	{
		AllocationValue = null;
		AllocationDescriptorAction = null;
		AllocationDescriptor = descriptor;
		return Self;
	}

	public IndexRoutingDescriptor Allocation(Action<Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocationDescriptor> configure)
	{
		AllocationValue = null;
		AllocationDescriptor = null;
		AllocationDescriptorAction = configure;
		return Self;
	}

	public IndexRoutingDescriptor Rebalance(Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalance? rebalance)
	{
		RebalanceDescriptor = null;
		RebalanceDescriptorAction = null;
		RebalanceValue = rebalance;
		return Self;
	}

	public IndexRoutingDescriptor Rebalance(Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalanceDescriptor descriptor)
	{
		RebalanceValue = null;
		RebalanceDescriptorAction = null;
		RebalanceDescriptor = descriptor;
		return Self;
	}

	public IndexRoutingDescriptor Rebalance(Action<Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalanceDescriptor> configure)
	{
		RebalanceValue = null;
		RebalanceDescriptor = null;
		RebalanceDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AllocationDescriptor is not null)
		{
			writer.WritePropertyName("allocation");
			JsonSerializer.Serialize(writer, AllocationDescriptor, options);
		}
		else if (AllocationDescriptorAction is not null)
		{
			writer.WritePropertyName("allocation");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingAllocationDescriptor(AllocationDescriptorAction), options);
		}
		else if (AllocationValue is not null)
		{
			writer.WritePropertyName("allocation");
			JsonSerializer.Serialize(writer, AllocationValue, options);
		}

		if (RebalanceDescriptor is not null)
		{
			writer.WritePropertyName("rebalance");
			JsonSerializer.Serialize(writer, RebalanceDescriptor, options);
		}
		else if (RebalanceDescriptorAction is not null)
		{
			writer.WritePropertyName("rebalance");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.IndexManagement.IndexRoutingRebalanceDescriptor(RebalanceDescriptorAction), options);
		}
		else if (RebalanceValue is not null)
		{
			writer.WritePropertyName("rebalance");
			JsonSerializer.Serialize(writer, RebalanceValue, options);
		}

		writer.WriteEndObject();
	}
}